package com.yeshine.opendata.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.JSONLibDataFormatSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * Created by taohj on 2014/4/17.
 */
public class JsonUtil {


    private static final SerializeConfig config;


    private static final SerializerFeature[] features = {SerializerFeature.WriteMapNullValue, //
            SerializerFeature.WriteNullListAsEmpty, //
            SerializerFeature.WriteNullNumberAsZero, //
            SerializerFeature.WriteNullBooleanAsFalse, //
            SerializerFeature.WriteNullStringAsEmpty, //
            SerializerFeature.BrowserCompatible
    };

    static {
        config = new SerializeConfig();
        config.put(java.util.Date.class, new JSONLibDataFormatSerializer()); //
        config.put(java.sql.Date.class, new JSONLibDataFormatSerializer()); //
    }


    public static String toString(Object object) {

        if (object == null) {
            return null;
        } else {
            return JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss", SerializerFeature.BrowserCompatible);
        }
    }


}
